using System;
using System.Collections;
using System.Data;
using System.Web.UI.WebControls;
using PHSRAG.Insight21.ClinicalTrials;
using PHSRAG.Insight21.Common.Pages;
using PHSRAG.Insight21.Context;
using PHSRAG.Insight21.Policy;
using PHSRAG.Insight21.SearchContext;
using PHSRAG.Utility;
using PHSRAG.WebControls;
using Constants = PHSRAG.Insight21.InsightUtilities.Constants;

namespace PHSRAG.Insight21
{
    /// <summary>
    /// Provides searching facilities and displays budget summaries.  Also provides for creating
    /// new budgets, deleting existing budgets and reporting functionality.
    /// </summary>
    public partial class BudgetBuilderSummary : NoCachePage
    {
        #region Constants

        private const string controlHost = "../Common/ControlHost.aspx?Load=";
        private const string CurrentPageIndexKey = "currentPageIndexKey_D4B51D05-112E-4346-AF5E-114F314325F9";
        private const string features = "'width=750,height=500,scrollbars=yes,resizable=yes,status=no'";
        private const string PageFileName = "BudgetBuilderSummary.aspx";
        private const string PageName = "Budget Summary";
        private const string pickerURL = "../ClinicalTrials/Controls/ProcedurePicker.ascx";
        private const string ProtocolIDsKey = "ProtocolIDs_CCB4DDA1-964F-4052-A99D-2613BB93CD2C";
        private const string ProtocolsKey = "Protocols_CCC0E511-8057-42bc-81C9-581A792E8C6B";
        private const string searchCriteriaCacheKey = "AP_SearchCriteria_150402B3-0393-409a-8BE9-0903DEB0C7D1";
        private const string searchCriteriaVersionCacheKey = "AP_Search_Version_C2D16769-9828-470f-80C3-2B2079029A08";
        private const string SearchCriteriaVersionKey = "sponsorGroupType_D4B51D05-112E-4346-AF5E-114F314325F9";
        private const string SortColumnKey = "SortColumn_B587BDE2-C8CC-4a87-8B02-2D431A5DA818";
        private const string SortDirectionKey = "SortAscending_BBC56095-F29E-47f2-BD2B-631B0C3C1FD5";
        private const int statusColumnIndex = 5;

        #endregion

        #region Instance Variables (Private)

        private ICachePolicy cachePolicy;
        private ICachePolicy pageCachePolicy;

        #endregion

        private Budget budget;
        protected Panel Panel1;

        #region Private Properties

        private BudgetSummaries BudgetSummaries
        {
            get
            {
                CommonSearchContext searchContext = (CommonSearchContext) cachePolicy.GetCachedObject(CommonSearchContext.CacheKey);
                int searchVersion = (searchContext == null) ? 0 : searchContext.GetSearchCriteria(Page.Request.Url.ToString()).Version;

                BudgetSummaries budgetSummaries = (BudgetSummaries) cachePolicy.GetCachedObject(BudgetSummaries.CacheKey);

                if (budgetSummaries == null ||
                    ((searchContext != null) && (searchVersion != SearchCriteriaVersion)) ||
                        cachePolicy.GetCachedObject("RefreshClinicalTrialBudgetResults") != null)
                {
                    UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
                    SearchCriteriaVersion = searchVersion;

                    if (budgetSummaries != null)
                    {
                        budgetSummaries.UnCache();
                    }

                    budgetSummaries = new BudgetSummaries(cachePolicy);
                    budgetSummaries.Search(searchContext.GetSearchCriteria(Page.Request.Url.ToString()));
                    budgetSummaries.Cache();
                    cachePolicy.UnCache("RefreshClinicalTrialBudgetResults");
                }
                return budgetSummaries;
            }
        }

        private int SearchCriteriaVersion
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.BudgetSummaryPageKey) as Hashtable;
                return (h == null || h[SearchCriteriaVersionKey] == null) ? 0 : (int) h[SearchCriteriaVersionKey];
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.BudgetSummaryPageKey) as Hashtable ?? new Hashtable();

                h[SearchCriteriaVersionKey] = value;
                pageCachePolicy.Cache(Keys.BudgetSummaryPageKey, h);
            }
        }

        private int CurrentPageIndex
        {
            get
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.BudgetSummaryPageKey) as Hashtable;
                return (h == null || h[CurrentPageIndexKey] == null) ? 0 : (int) h[CurrentPageIndexKey];
            }
            set
            {
                Hashtable h = pageCachePolicy.GetCachedObject(Keys.BudgetSummaryPageKey) as Hashtable ?? new Hashtable();
                h[CurrentPageIndexKey] = value;
                budgetSummaryGrid.CurrentPageIndex = value;
                pageCachePolicy.Cache(Keys.BudgetSummaryPageKey, h);
            }
        }

        #endregion

        #region Event Handlers

        /// <summary>
        /// Handler for the event raised by the CommonSearch control when the "Clear Selection" buttion is clicked upon.
        /// The control clears the criretria (specific to this module).
        /// Since in the page life-cycle, the Load occurs before the Clear event, we have to instigate a re-load of the
        /// data grid to refelect the fact that the search criteria has been cleared.
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Argument associated with the event</param>
        protected void OnClearSelection(object sender, CommandEventArgs e)
        {
            SearchCriteriaVersion = -1;
            LoadDataGrid();
        }

        protected void OnPageLoad(object sender, EventArgs e)
        {
            try
            {
                annunciator.Message = string.Empty;
                cachePolicy.Cache(Keys.IsFromBudgetBuilderSummaryKey, true);
                if (!IsPostBack)
                {
                    ((ExpansionToggler) expandingPanel.FindControl("expansionToggler")).HelpText =
                        Constants.SearchHelpText;

                    breadCrumb.Add(PageName, PageFileName, Settings.GetKeyValue("BreadCrumb.SummaryPageLevel", 1));
                    cachePolicy.UnCache(Keys.IncomingDataKey);
                    budgetSummaryGrid.PageSize = Settings.GetKeyValue("DataGrid.ItemsPerPage", 20);
                    LoadDataGrid();
                }
                if (institution.SelectedValue == "ClinicalTrialBudgetInstitutionMGH")
                {
                    procedurePicker.Attributes["onclick"] = string.Format("window.open('{0}{1}&Institution={2}&Caller={3}', 'Picker', {4});return false;", controlHost, pickerURL, "ClinicalTrialBudgetInstitutionMGH", ID, features);
                }
                if (institution.SelectedValue == "ClinicalTrialBudgetInstitutionBWH")
                {
                    procedurePicker.Attributes["onclick"] = string.Format("window.open('{0}{1}&Institution={2}&Caller={3}', 'Picker', {4});return false;", controlHost, pickerURL, "ClinicalTrialBudgetInstitutionBWH", ID, features);
                }
            }
            catch (Exception ex)
            {
                annunciator.Message = String.Format("{0} loading."
                    , ExceptionReport.GetExceptionInfo(ex, false));
            }
        }

        private void SetupPickers()
        {
            UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
            string pickerURL = "../ClinicalTrials/Controls/procedurePicker.ascx";
            string features = "'width=700,height=500,scrollbars=yes,resizable=yes,status=no'";
            procedurePicker.Attributes["class"] = "Button";

            if (!userContext.IsUserSysAdmin)
            {
                if (userContext.Institution == "MGH")
                {
                    if (!Page.IsPostBack)
                    {
                        institution.Items.Insert(0, new ListItem("MGH", "ClinicalTrialBudgetInstitutionMGH"));
                    }
                }
                if (userContext.Institution == "BWH")
                {
                    if (!Page.IsPostBack)
                    {
                        institution.Items.Insert(0, new ListItem("BWH", "ClinicalTrialBudgetInstitutionBWH"));
                    }
                }
                if (userContext.Institution == "PHS")
                {
                    if (!Page.IsPostBack)
                    {
                        institution.Items.Insert(0, new ListItem("BWH", "ClinicalTrialBudgetInstitutionBWH"));
                        institution.Items.Insert(1, new ListItem("MGH", "ClinicalTrialBudgetInstitutionMGH"));
                    }
                }
            }
            if (userContext.IsUserSysAdmin)
            {
                if (!Page.IsPostBack)
                {
                    institution.Items.Insert(0, new ListItem("BWH", "ClinicalTrialBudgetInstitutionBWH"));
                    institution.Items.Insert(1, new ListItem("MGH", "ClinicalTrialBudgetInstitutionMGH"));
                }
            }

            if (institution.SelectedValue == "ClinicalTrialBudgetInstitutionMGH")
            {
                procedurePicker.Attributes["onclick"] = string.Format("window.open('{0}{1}&Institution={2}&Caller={3}', 'Picker', {4});return false;", controlHost, pickerURL, "ClinicalTrialBudgetInstitutionMGH", ID, features);
            }
            if (institution.SelectedValue == "ClinicalTrialBudgetInstitutionBWH")
            {
                procedurePicker.Attributes["onclick"] = string.Format("window.open('{0}{1}&Institution={2}&Caller={3}', 'Picker', {4});return false;", controlHost, pickerURL, "ClinicalTrialBudgetInstitutionBWH", ID, features);
            }
        }

        private void OnPickerClick(object sender, EventArgs e)
        {
            cachePolicy.Cache(Keys.IsFromBudgetBuilderSummaryKey, true);
        }

        /// <summary>
        /// Event handler for processing search requests from the common search control
        /// </summary>
        /// <param name="e"></param>
        protected void OnSearch(SearchCriteriaArgs e)
        {
            if (SearchCriteriaVersion == -1)
            {
                ++SearchCriteriaVersion;
            }

            CurrentPageIndex = 0;
            LoadDataGrid();
        }

        /// <summary>
        /// Event handler for processing budget delete requests
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnDelete(object sender, EventArgs e)
        {
            BudgetSummaries budgetSummaries = BudgetSummaries;
            DataTable budgetsDataTable = budgetSummaries.GetDataContainer().Tables["original"];
            foreach (DataGridItem item in budgetSummaryGrid.Items)
            {
                if (((CheckBox) item.FindControl("deleteBudget")).Checked)
                {
                    try
                    {
                        ArrayList attachmentList = BudgetAttachment.GetDocuments(Convert.ToInt32(item.Cells[0].Text), cachePolicy);
                        foreach (object o in attachmentList)
                        {
                            BudgetAttachment.DeleteAttachment(((BudgetAttachment) o).DocumentId);
                        }
                        budgetsDataTable.Select(string.Format("{0}{1}", "Id = ", item.Cells[0].Text))[0].Delete();
                    }
                    catch (Exception ex)
                    {
                        annunciator.Title = string.Format("Error deleting selected clinical trials: {0}", ex.Message);
                    }
                }
            }
            budgetSummaries.Save(DataAccess.GetConnectionString(), null);
            budgetSummaries.UnCache();

            BudgetSummaries summaries = BudgetSummaries;
            LoadDataGrid();
        }

        private void OnHeaderNavigate(object sender, CommandEventArgs e)
        {
            PurgeItem();
        }

        protected void PurgeItem()
        {
            cachePolicy.UnCache(Keys.IsFromBudgetBuilderSummaryKey);
        }

        protected void OnNewBudget(object sender, EventArgs e)
        {
            PurgeItem();
            Hashtable dictionary = new Hashtable();
            dictionary.Add(Keys.BudgetIdKey, 0);
            pageCachePolicy.Cache(Keys.IncomingDataKey, dictionary);
            Response.Redirect(Settings.GetKeyValue("SubNavigation.ClinicalTrials.BudgetSetupURL", ""));
        }

        private void OnCloneBudget(object sender, EventArgs e)
        {
            BudgetSummaries budgetSummaries = BudgetSummaries;
            DataTable budgetsDataTable = budgetSummaries.GetDataContainer().Tables["original"];
            foreach (DataGridItem item in budgetSummaryGrid.Items)
            {
                if (((CheckBox) item.FindControl("cloneBudget")).Checked)
                {
                    Hashtable h = (Hashtable) cachePolicy.GetCachedObject(Keys.IncomingDataKey);
                    budget = new Budget(cachePolicy);
                    UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
                    int domainUserId = userContext.DomainUserId;
                    int newBudgetId = Budget.CloneThisBudget(Convert.ToInt32(item.Cells[0].Text));
                    budget.Load(DataAccess.GetConnectionString(), newBudgetId, domainUserId);
                    budget.Cache();
                    budgetSummaries.UnCache();
                    if (budget.StatusCode == "ClinicalTrialBudgetStatusFinal")
                    {
                        Response.Redirect(Settings.GetKeyValue("SubNavigation.ClinicalTrials.BudgetSummaryURL", ""));
                    }
                    else
                    {
                        Response.Redirect(Settings.GetKeyValue("SubNavigation.ClinicalTrials.BudgetSetupURL", ""));
                    }
                }
            }
        }

        #region Pagination Event Handlers

        private void OnPreviousPage(object sender, CommandEventArgs e)
        {
            --CurrentPageIndex;
            LoadDataGrid();
        }

        private void OnLastPage(object sender, CommandEventArgs e)
        {
            CurrentPageIndex = topPager.PageCount - 1;
            LoadDataGrid();
        }

        /// <summary>
        /// Handler for the event raised when the NextPage link in clicked in the Pager control.
        /// Increment the current page index, bind the datagrid with data and manage navigation links.
        /// </summary>
        /// <param name="sender">Control which rasied the event</param>
        /// <param name="e">Arguments associated with the event</param>
        private void OnNextPage(object sender, CommandEventArgs e)
        {
            ++CurrentPageIndex;
            LoadDataGrid();
        }

        private void OnFirstPage(object sender, CommandEventArgs e)
        {
            CurrentPageIndex = 0;
            LoadDataGrid();
        }

        #endregion

        #region DataGrid Event Handlers

        private void OnItemCommand(object source, DataGridCommandEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                if (e.CommandName == "SelectBudget")
                {
                    Hashtable dictionary = new Hashtable();
                    dictionary.Add(Keys.BudgetIdKey, Convert.ToInt32(e.Item.Cells[0].Text));
                    pageCachePolicy.Cache(Keys.IncomingDataKey, dictionary);

                    LoadBudget();
                    PurgeItem();
                    if (budget.StatusCode == "ClinicalTrialBudgetStatusFinal")
                    {
                        Response.Redirect(Settings.GetKeyValue("SubNavigation.ClinicalTrials.BudgetSummaryURL", ""));
                    }
                    else
                    {
                        Response.Redirect(Settings.GetKeyValue("SubNavigation.ClinicalTrials.BudgetSetupURL", ""));
                    }
                }
            }
        }

        private void LoadBudget()
        {
            budget = (Budget) cachePolicy.GetCachedObject(Budget.CacheKey);

            if (Session[Keys.IncomingDataKey] != null)
            {
                Hashtable h = (Hashtable) cachePolicy.GetCachedObject(Keys.IncomingDataKey);
                int budgetId = (int) h[Keys.BudgetIdKey];
                UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
                int domainUserId = userContext.DomainUserId;
                if (budgetId == 0)
                {
                    // New Budget
                    budget = new Budget(cachePolicy);
                    budget.StatusCode = "ClinicalTrialBudgetStatusInProgress";
                    System.Diagnostics.Trace.Assert(userContext != null);
                    budget.OriginatorPersonId = userContext.PersonId;
                    budget.Cache();
                }
                else if (budget == null || budget.Id != budgetId)
                {
                    budget = new Budget(cachePolicy);
                    budget.Load(DataAccess.GetConnectionString(), budgetId, domainUserId);
                    budget.Cache();
                }
                Session.Remove(Keys.IncomingDataKey);
            }
        }


        private void OnItemCreated(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Header)
            {
                // Ideally, we would like to set the width of each column such that the header text does not wrap. This
                // is pretty easy, as evidenced by the following (commented) block of code. Why then is the code commented?
                // Well, this gets us into an interesting pickle. Let me elucidate:
                // When column widths are not explictly set, the header text MIGHT wrap, but when the size of the browser
                // window is increased, column widths also increase, automatically filling the increased space. This is the
                // desired behavior. However, if the column widths are EVER set explicitly, the contents won't expand to
                // fill the available space. The rendered HTML will have the "Width" setting, and that clamsp the width
                // hard. This is NOT the desired behavior.
                // It therefor appers that we can either have the cake or eat it. I have decided to eat the cake and not
                // set column width. Hence the block of code is commented.
                // Why then, you ask, is the code still here? Just to show you it COULD be done with the mentioned caveat.
                //				Bitmap bm = new Bitmap(1, 1);
                //				Graphics g = Graphics.FromImage(bm);
                //
                //				for (int c = 0; c < dataGrid.Columns.Count; ++c)
                //				{
                //					SizeF size = g.MeasureString(dataGrid.Columns[c].HeaderText, new Font("Verdana", 10));
                //					dataGrid.Columns[c].ItemStyle.Width = Unit.Pixel((int)Math.Ceiling(size.Width));
                //				}

                BudgetSummaries budgetSummaries = BudgetSummaries;
                Label sortSymbol = new Label();
                sortSymbol.Text = budgetSummaries.SortAscending ? Constants.SortAscendingText : Constants.SortDescendingText;
                sortSymbol.Font.Name = Constants.SortSymbolFontName;

                Hashtable columnMap = new Hashtable();
                foreach (DataGridColumn column in budgetSummaryGrid.Columns)
                {
                    columnMap[column.SortExpression] = budgetSummaryGrid.Columns.IndexOf(column);
                }

                string sortColumn = budgetSummaries.SortColumn;
                if (columnMap.ContainsKey(sortColumn))
                {
                    (e.Item.Cells[(int) columnMap[sortColumn]]).Controls.Add(sortSymbol);
                }
            }
        }

        private void OnItemDataBound(object sender, DataGridItemEventArgs e)
        {
            try
            {
                UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
                int rightsBitmask = userContext.RightBitmask;

                if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
                {
                    if (CTAccessHelper.IsUserAdministrator(rightsBitmask) == false)
                    {
                        //based on the rights make delete checkbox visible or not visible.
                        int userRecordRights = Int32.Parse(e.Item.Cells[11].Text);
                        if (CTAccessHelper.IsUserModifyFinalDeleteBudget(userRecordRights) == false)
                        {
                            e.Item.Cells[10].Visible = false;
                        }
                        if (CTAccessHelper.IsUserCreateNewBudget(userRecordRights) == false)
                        {
                            e.Item.Cells[9].Visible = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                annunciator.Message = String.Format("{0} while attempting to format columns."
                    , ExceptionReport.GetExceptionInfo(ex, false));
            }
        }

        private void OnSort(object source, DataGridSortCommandEventArgs e)
        {
            if (e.SortExpression != string.Empty)
            {
                BudgetSummaries.Sort(e.SortExpression);
                LoadDataGrid();
            }
        }

        #endregion

        #endregion

        #region Private Methods

        #region Pager Methods

        private void ManagePagination()
        {
            int currentPageIndex = CurrentPageIndex;
            budgetSummaryGrid.CurrentPageIndex = currentPageIndex;

            int startIndex = currentPageIndex*budgetSummaryGrid.PageSize;

            bottomPager.FirstRecord = topPager.FirstRecord = startIndex + 1;
            bottomPager.LastRecord = topPager.LastRecord =
                Math.Min(startIndex + budgetSummaryGrid.PageSize, BudgetSummaries.Count);

            bottomPager.EnableFirstPage = topPager.EnableFirstPage =
                bottomPager.EnablePreviousPage = topPager.EnablePreviousPage =
                    (CurrentPageIndex != 0);

            bottomPager.EnableLastPage = topPager.EnableLastPage =
                bottomPager.EnableNextPage = topPager.EnableNextPage =
                    (CurrentPageIndex != (topPager.PageCount - 1));
        }

        #endregion

        private void LoadDataGrid()
        {
            try
            {
                BudgetSummaries budgetSummaries = BudgetSummaries;
                budgetSummaryGrid.VirtualItemCount = bottomPager.RecordCount = topPager.RecordCount = budgetSummaries.Count;

                int currentPageIndex = CurrentPageIndex;
                int pageCount = (topPager.RecordCount/budgetSummaryGrid.PageSize) +
                    (((topPager.RecordCount%budgetSummaryGrid.PageSize) == 0) ? 0 : 1);
                bottomPager.PageCount = topPager.PageCount = pageCount;
                bottomPager.CurrentPage = topPager.CurrentPage = currentPageIndex + 1;

                ArrayList budgetList = budgetSummaries.GetBudgetList(currentPageIndex*budgetSummaryGrid.PageSize, budgetSummaryGrid.PageSize);
                budgetSummaryGrid.DataSource = budgetList;
                budgetSummaryGrid.DataBind();

                if (budgetSummaryGrid.VirtualItemCount > 0)
                {
                    gridContainer.Visible = delete.Visible = clone.Visible = true;
                    ManagePagination();
                }
                else
                {
                    gridContainer.Visible = delete.Visible = clone.Visible = false;
                    annunciator.Message = "No budgets found matching the search criteria.";
                }

                //module rights were found
                UserContext userContext = (UserContext) cachePolicy.GetCachedObject(UserContext.CacheKey);
                int rightsBitmask = userContext.RightBitmask;

                if (rightsBitmask != 0)
                {
                    if (budgetSummaryGrid.Items.Count > 0)
                    {
                        if (!CTAccessHelper.IsUserAdministrator(rightsBitmask))
                        {
                            if (CTAccessHelper.IsUserCreateNewBudget(rightsBitmask) == false)
                            {
                                createNewBudget.Visible = false;
                                procedurePicker.Visible = false;
                                institution.Visible = false;
                                institutionLabel.Visible = false;
                            }
                        }
                    }
                    else
                    {
                        if (!CTAccessHelper.IsUserAdministrator(rightsBitmask))
                        {
                            gridContainer.Visible = false;
                            if (!CTAccessHelper.IsUserCreateNewBudget(rightsBitmask))
                            {
                                createNewBudget.Visible = false;
                                procedurePicker.Visible = false;
                                institution.Visible = false;
                                institutionLabel.Visible = false;
                            }
                        }
                    }
                }
                else
                {
                    createNewBudget.Visible = false;
                    gridContainer.Visible = false;
                    procedurePicker.Visible = false;
                    institution.Visible = false;
                    institutionLabel.Visible = false;
                    annunciator.Message = "You do not have rights to view or create Budgets.  Please contact the key giver or Insight Help Desk.";
                    throw (new Exception(annunciator.Message));
                }
            }
            catch (Exception e)
            {
                bottomPager.Visible = topPager.Visible = budgetSummaryGrid.Visible = false;
                annunciator.Message = ExceptionReport.GetExceptionInfo(e, false);
                annunciator.Visible = true;
            }
        }

        #endregion

        #region Web Form Designer generated code

        ///<summary>Initializes components used by the page.</summary>
        protected override void OnPreRender(EventArgs e)
        {
            SetupPickers();
            base.OnPreRender(e);
        }

        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);

            cachePolicy = (Policy.ICachePolicy) Session[Policy.Names.CachePolicyKey];
            pageCachePolicy = (Policy.ICachePolicy) Session[Policy.Names.PageCachePolicyKey];

            topPager.NextPage += new CommandEventHandler(OnNextPage);
            topPager.PreviousPage += new CommandEventHandler(OnPreviousPage);
            topPager.FirstPage += new CommandEventHandler(OnFirstPage);
            topPager.LastPage += new CommandEventHandler(OnLastPage);

            bottomPager.NextPage += new CommandEventHandler(OnNextPage);
            bottomPager.PreviousPage += new CommandEventHandler(OnPreviousPage);
            bottomPager.FirstPage += new CommandEventHandler(OnFirstPage);
            bottomPager.LastPage += new CommandEventHandler(OnLastPage);
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.budgetSummaryGrid.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemCreated);
            this.budgetSummaryGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnItemCommand);
            this.budgetSummaryGrid.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.OnSort);
            this.budgetSummaryGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemDataBound);
            this.ID = "budgetBuilderSummary";
            this.delete.Click += new System.EventHandler(this.OnDelete);
            this.Load += new System.EventHandler(this.OnPageLoad);
            createNewBudget.Click += new EventHandler(OnNewBudget);
            clone.Click += new EventHandler(OnCloneBudget);
        }

        #endregion
    }
}